<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入名称查询" v-model="queryParam.customerName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="客户编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入客户编号查询" v-model="queryParam.customerNo"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="销售人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入销售人员查询" v-model="queryParam.salespersonName"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator"  style="margin-top: 5px">
          <a-button   @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button   @click="batchDel" icon="delete">删除</a-button>
          <a-button   @click="batchSetStatus(true)" icon="check-square">启用</a-button>
          <a-button   @click="batchSetStatus(false)" icon="close-square">禁用</a-button>
          <a-button   @click="handleImportXls()" icon="import">导入</a-button>
          <a-button v-if="btnEnableList.indexOf(3)>-1" @click="handleExportXls('客户信息')" icon="download">导出</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider   type="vertical" />
              <a-popconfirm   title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <span slot="receivable_balance" slot-scope="text, record">
              {{ text }}
              <a-button @click="handlereceivableBalance(record)">查看</a-button>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <a-modal title="应收余额" :visible="visible" :confirm-loading="confirmLoading" @ok="visible = false"  @cancel="visible = false">
          <a-table size="middle" bordered rowKey="id2" :columns="columns2" :dataSource="dataSource2">
            <span slot="billsType" slot-scope="text">
              {{ text == 'sales' ? '销售单' : text == 'PurchaseSalesExpenses' ? '销售费用单' : '其他单据' }}
            </span>
            <template slot="action" slot-scope="text, record">
              <a slot="action" @click="handleBillsType(record)">查看</a>
            </template>
          </a-table>
        </a-modal>
        <customer-modal ref="modalForm" @ok="modalFormOk"></customer-modal>
        <import-file-modal ref="modalImportForm" @ok="modalFormOk"></import-file-modal>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
  import CustomerModal from './modules/CustomerModal'
  import ImportFileModal from '@/components/tools/ImportFileModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JDate from '@/components/jeecg/JDate'
  import Vue from 'vue'
  export default {
    name: "CustomerList",
    mixins:[JeecgListMixin],
    components: {
      CustomerModal,
      ImportFileModal,
      JDate
    },
    data () {
      return {
              visible: false,
        labelCol: {
          span: 5
        },
        wrapperCol: {
          span: 18,
          offset: 1
        },
        // 查询条件
        queryParam: {
          salespersonName:'',
          type:'客户',
          customerNo:'',
          customerName:''
        },
        ipagination:{
          pageSizeOptions: ['10', '20', '30', '100', '200']
        },
          columns2: [
        {
          title: '单据类型',
          dataIndex: 'billsType',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'billsType' },
        },
        { title: '单据编号', dataIndex: 'billNo', width: 100, align: 'center' },
        { title: '应付金额', dataIndex: 'receivable_balance', width: 100, align: 'center' 
        },
        // {
        //   title: '查看',
        //   dataIndex: 'action',
        //   width: 100,
        //   align: 'center',
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: 100,
            align:"center",
            scopedSlots: { customRender: 'action' },
          },
          { title: '名称',dataIndex:        'customerName',width:150,align:"left"},
          { title: '编号', dataIndex:       'customerNo',width:100,align:"left"},
          { title: '收款条件', dataIndex:   'paymentTerms',width:100,align:"left"},
          { title: '地区', dataIndex:       'region',width:100,align:"left"},
          { title: '销售人员', dataIndex:    'salespersonName',width:100,align:"left"},
          { title: '联系人', dataIndex:      'contactPerson',width:100,align:"left"},
          { title: '税号', dataIndex: 'taxIdentificationNumber',width:100,align:"left"},
          { title: '开户行', dataIndex: 'bankName',width:100,align:"left"},
          { title: '帐户', dataIndex: 'bankAccount',width:100,align:"left"},
          { title: '电话', dataIndex: 'phone',width:100,align:"left"},
          { title: '应收余额', dataIndex: 'receivableBalance',width:100,align:"left",
           scopedSlots: { customRender: 'receivable_balance' }},
          { title: '线路', dataIndex: 'associatedRoute',width:100,align:"left"},
          { title: '省', dataIndex: 'province',width:100,align:"left"},
          { title: '市', dataIndex: 'city',width:100,align:"left"},
          { title: '区', dataIndex: 'district',width:100,align:"left"},
          { title: '送货地址', dataIndex: 'deliveryAddress',width:100,align:"left"},
          { title: '备注', dataIndex: 'remark',width:100,align:"left"},
          { title: '状态',dataIndex: 'status',width:60, align:"center",
            scopedSlots: { customRender: 'customRenderFlag' }
          }
        ],
        url: {
          list: "/customer/list",
          delete: "/customer/delete",
          deleteBatch: "/customer/deleteBatch",
          importExcelUrl: "/customer/importCustomer",
          exportXlsUrl: "/customer/exportExcel",
          batchSetStatusUrl: "/customer/batchSetStatus"
        }
      }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`;
      }
    },
    created() {
    },
    methods: {
      handlereceivableBalance(recode) {
      this.visible = true
      this.dataSource2 = recode.customerReceivableBalanceDetails
    },
      searchReset() {
        this.queryParam = {
          type:'客户',
        }
        this.loadData(1);
      },
      handleImportXls() {
        let importExcelUrl = this.url.importExcelUrl
        let templateUrl = '/doc/customer_template.xls'
        let templateName = '客户Excel模板[下载]'
        this.$refs.modalImportForm.initModal(importExcelUrl, templateUrl, templateName);
        this.$refs.modalImportForm.title = "客户导入";
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
        if(this.btnEnableList.indexOf(1)===-1) {
          this.$refs.modalForm.isReadOnly = true
        }
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>